let v = new Vue({
   el:'#main-container',
    data:{
       pageInfo:{
           pageSize:5
       },
       app:{},
        active:true
    },
    methods:{
       findAll:function (page,pageSize) {
           axios({
               url:`manager/app/list/${page}/${pageSize}`
           }).then(
               resp => {
                   this.pageInfo = resp.data.obj;
               }
           ).catch(
               error => {
                   console.log(error);
               }
           )
       },
        toUpdate:function(app){
            layer.obj=app;
            layer.open({
                type: 2,
                title: '更新',
                area: ['60%', '60%'],
                content: 'manager/app/toUpdate',
                end:() => {
                    if(!layer.success){
                        this.findAll(1,this.pageInfo.pageSize);
                    }
                }
            })
        },
        insert:function () {
            axios({
                url:'manager/app/insert',
                method:'post',
                data:this.app
            }).then(resp => {
                this.app = {};
                layer.msg(resp.data.msg);
                this.active = true;
            }).catch(error => {
                layer.msg(error.message);
            })
        },
        change:function(b){
           this.active = b;
        },
        ifDelete:function(id){
            layer.msg('你确定删除么？', {
                time: 0 //不自动关闭
                ,btn: ['是', '否']
                ,yes: ()=>{
                    //选择是则发送删除请求
                    axios({
                        url:`manager/app/delete/${id}`,
                        method:'delete',
                    }).then(resp => {
                        layer.msg(resp.data.msg);
                        this.findAll(this.pageInfo.pageNum,this.pageInfo.pageSize);
                    }).catch(error => {
                        layer.msg(error.message);
                    })
                }
            });
        }
    },
    created:function () {
        this.findAll(1,5);
    }
})